//
//  SSSingleTableViewCell.m
//  textDemo
//
//  Created by Esther on 2017/2/20.
//  Copyright © 2017年 Esther. All rights reserved.
//

#import "SSSingleTableViewCell.h"
#import <UIImageView+WebCache.h>

@interface SSSingleTableViewCell()

@property(nonatomic, strong) UIImageView *iconImage;
@property(nonatomic, strong) UIImageView *countryImage;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UILabel *contentLabel;
@property(nonatomic, strong) UILabel *pricLabel;
@property(nonatomic, strong) UIButton *buyCarButton;


@end

@implementation SSSingleTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self addSubview:self.iconImage];
        [self addSubview:self.countryImage];
        [self addSubview:self.titleLabel];
        [self addSubview:self.contentLabel];
        [self addSubview:self.pricLabel];
        [self addSubview:self.buyCarButton];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    #pragma mark - 约束
    __weak typeof (self) weakSelf = self;
    [_iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(140, 140));
        make.centerY.equalTo(weakSelf.mas_centerY);
        make.left.equalTo(weakSelf.mas_left).offset(5);
        
    }];
    
    [_countryImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(25, 20));
        make.left.equalTo(weakSelf.iconImage.mas_left).offset(8);
        make.top.equalTo(weakSelf.iconImage.mas_top).offset(8);
        
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.mas_right).offset(-15);
        make.left.equalTo(weakSelf.iconImage.mas_right).offset(6);
        make.top.equalTo(weakSelf.mas_top).offset(25);
        make.height.equalTo(@15);
    }];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.titleLabel.mas_bottom).offset(7);
        make.right.equalTo(weakSelf.mas_right).offset(-15);
        make.left.equalTo(weakSelf.iconImage.mas_right).offset(6);
        make.height.equalTo(@60);
    }];
    
    [_pricLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@15);
        make.left.equalTo(weakSelf.iconImage.mas_right).offset(6);
        make.right.equalTo(weakSelf.buyCarButton.mas_left).offset(-20);
        make.bottom.equalTo(weakSelf.mas_bottom).offset(-23);
        
    }];
    
    [_buyCarButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(37, 37));
        make.right.equalTo(weakSelf.mas_right).offset(-45);
        make.bottom.equalTo(weakSelf.mas_bottom).offset(-20);
        
    }];
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
}

- (void)setFirstSell:(SSFirstSell *)firstSell{
    _firstSell = firstSell;
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:firstSell.img] placeholderImage:[UIImage imageNamed:@"iconImage"]];
    
    [self.countryImage sd_setImageWithURL:[NSURL URLWithString:firstSell.pre_img] placeholderImage:[UIImage imageNamed:@"iconImage"]];
    
    self.titleLabel.text = firstSell.name;
    self.contentLabel.text = firstSell.pm_desc;
    self.pricLabel.text = [NSString stringWithFormat:@"%f",firstSell.partner_price];
}

#pragma mark -
#pragma mark - 懒加载
- (UIImageView *)iconImage{
    if (!_iconImage) {
        _iconImage = [[UIImageView alloc] init];
        
    }
    return _iconImage;
}

- (UIImageView *)countryImage{
    if (!_countryImage) {
        _countryImage = [[UIImageView alloc] init];
        
    }
    return _countryImage;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:14.0];
        _titleLabel.textColor = [UIColor ss_colorWithRed:81 green:81 blue:81];
        
    }
    return _titleLabel;
}

- (UILabel *)contentLabel{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.textColor = [UIColor ss_colorWithRed:35 green:35 blue:35];
        _contentLabel.font = [UIFont systemFontOfSize:13.0];
        _contentLabel.numberOfLines = 3;
    }
    return _contentLabel;
}

- (UILabel *)pricLabel{
    if (!_pricLabel) {
        _pricLabel = [[UILabel alloc] init];
        
    }
    return _pricLabel;
}

- (UIButton *)buyCarButton{
    if (!_buyCarButton) {
        _buyCarButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_buyCarButton setImage:[UIImage imageNamed:@"限时特卖界面购物车图标"] forState:(UIControlStateNormal)];
         
    }
    return _buyCarButton;
}








@end
